<template>
	<theme-box title="通知添加">
		<form method="post" action="" class="form-horizontal" @submit.prevent v-el:form>
			<div class="box-body">
				<form-input title="通知标题" :required=true :value="title" name="title"></form-input>
				<form-input title="通知简介" :required=true :value="subTitle" name="subTitle"></form-input>
				<form-group title="通知内容">
					<textarea class="form-control" rows="4" maxlength="100" name="content"></textarea>
				</form-group>
				<form-input title="单位" :required=true name="unit" type="unit"></form-input>
				<form-group title="通知时间">
					<div class="form-inline">
							<form-date class="inline" label="开始日期" name="beginTime"></form-date>
							<form-date class="inline" label="结束日期" name="endTime"></form-date>
					</div>					
				</form-group>
			</div>
			<!-- /.box-body -->
			<div class="box-footer">
				<v-button type="reset" @click="reset">重置</v-button>
				<v-button type="submit" theme="primary" class="pull-right">确认</v-button>
			</div>
			<!-- /.box-footer -->
		</form>
	</theme-box>
</template>

<script>
	
	var serialize = require('form-serialize');

	export default {
		created() {
				let self = this;
				this.$post({
					url: "/api/v1" + projectName_Url + "/wechat/notice/add.html"
				}).then(response => {
					//self.roleList = response.content.roleList;
					self.$set("roleList",response.content.roleList)
				});
			},
			data: () => ({
				title: "",
				subTitle: "",
				content: "",
				unit: "",
				unit: "",
				unit: "",
				roleList: []
			}),
			ready: function () {
				let self = this;
				$(this.$els.form).submit(function () {
					return false;
				})
				$(this.$els.form).validate({
					submitHandler: async function () {
						let form = this.currentForm;

						$(form).find("input").each(function () {
							$(this).val($.trim($(this).val()));
						});

						let _data = serialize(form, {
							hash: true
						});

						self.$post({
							url: "/api/v1" + projectName_Url + "/console/console/opr/add.html",
							method: 'POST',
							data: _data
						}).then(response => {

							let data = {
								title: "操作成功",
								content: "是否进入管理员列表查看?"
							}
							Midway.confirm(data).then(function () {	
									self.$route.router.go('/admin/list');				
							})
							form.reset();
						});

					},
					rules: {
						operatorName: {
							required: true,
							minlength: 4
						},
						operatorDsc: {},
						operatorPwd: {
							required: true,
							minlength: 6
						}

					},
					messages: {
						operatorName: {
							required: "账号为必填项",
							minlength: "账号不少于4个字符"
						},
						operatorDsc: {},
						operatorPwd: {
							required: "密码为必填项",
							minlength: "密码不少于六位"
						}
					}
				});

			},
			methods: {
				reset() {
					$("label.error").remove();
					this.$els.form.reset();
				}
			}
	}
</script>
